//
//  AppDelegate.m
//  WJBSApp
//
//  Created by dllo on 16/7/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "WJHeaderViewController.h"
#import "WJDataManager.h"
//#import <ShareSDK/ShareSDK.h>
#import "WJTabBarViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc{
    [super dealloc];
    [_window release];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// 将引导页设置为跟视图控制器
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    WJHeaderViewController *headerView = [[WJHeaderViewController alloc]init];
    WJTabBarViewController *tabbar = [[WJTabBarViewController alloc]init];
    tabbar.view.backgroundColor = [UIColor whiteColor];

    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"welcome"] isEqualToString:@"we"]) {
        NSLog(@"不是第一次运行");
        self.window.rootViewController = tabbar;
    }
    else{
        
        NSLog(@"第一次运行");
        self.window.rootViewController = headerView;
        [[NSUserDefaults standardUserDefaults] setObject:@"we" forKey:@"welcome"];
    }

    
    [_window release];

//  创建文件夹
    [[NSFileManager defaultManager] createDirectoryAtPath:KESHAN withIntermediateDirectories:YES attributes:nil error:nil];
    
    [[NSFileManager defaultManager] createDirectoryAtPath:NOSHAN withIntermediateDirectories:YES attributes:nil error:nil];

    [[NSFileManager defaultManager] createDirectoryAtPath:VIDEO withIntermediateDirectories:YES attributes:nil error:nil];
    
    [[NSFileManager defaultManager] createDirectoryAtPath:AUDIO withIntermediateDirectories:YES attributes:nil error:nil];
    
    
// 创建数据库表格
    [[WJDataManager shareFMDB] openDB];
    [[WJDataManager shareFMDB] createFollowTable];
    [[WJDataManager shareFMDB] createFirTable];
    [[WJDataManager shareFMDB] createSecTable];
    [[WJDataManager shareFMDB] createPublishTable];
    [[WJDataManager shareFMDB] createPicTable];
    
    NSLog(@"%@",NSHomeDirectory());

    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[NSUserDefaults standardUserDefaults] setValue:@"asdad" forKey:@"LogInEssEnce"];
    [[NSUserDefaults standardUserDefaults] setValue:@"4545" forKey:@"LogInMe"];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
